package midi;

import java.util.HashMap;
import java.util.Map;

public class Scale {

	private final static Map<String, int[]> scales;

	public final static String CHROMATIC = "Chromatic";
	public final static String IONIAN = "Ionian";
	public final static String DORIAN = "Dorian";
	public final static String PHRYGIAN = "Phrygian";

	private final static int C = 0;
	private final static int C_SHARP = 1;
	private final static int D = 2;
	private final static int D_SHARP = 3;
	private final static int E = 4;
	private final static int E_SHARP = 5;
	private final static int F = 5;
	private final static int F_SHARP = 6;
	private final static int G = 7;
	private final static int G_SHARP = 8;
	private final static int A = 9;
	private final static int A_SHARP = 10;
	private final static int B = 11;
	private final static int B_SHARP = 12;

	static {
		scales = new HashMap<String, int[]>();
		scales.put(CHROMATIC, new int[] { C, C_SHARP, D, D_SHARP, E, F, F_SHARP, G, G_SHARP, A, A_SHARP, B });
		scales.put(IONIAN, new int[] { C, D, E, F, G, A, B });
		scales.put(DORIAN, new int[] { C, D, D_SHARP, F, G, A, A_SHARP });
		scales.put(PHRYGIAN, new int[] { C, C_SHARP, D_SHARP, F, G, G_SHARP, A_SHARP });
	}

	private String scale;

	public void setScale(String scale) {
		this.scale = scale;
	}

	public String getScale() {
		return this.scale;
	}

	public int getKey(int position, int transposition) {
		int scaleLength = scales.get(this.scale).length;
		return ((scales.get(this.scale)[position % scaleLength])) + ((position / scaleLength) * (1 + scales.get(this.scale)[scaleLength - 1])) + transposition;
	}

}
